// import bcrypt from 'bcryptjs'
const bcrypt = require('bcryptjs')
// 【同步加密和验证】
export const encrypt = (pass: string): string => {
  // 随机字符串
  const salt: string = bcrypt.genSaltSync(10);
  // 对明文加密
  const hash: string = bcrypt.hashSync(pass, salt);
  return hash;
}

// 验证比对,返回布尔值表示验证结果 true表示一致，false表示不一致
export const compare = (pass: string, hash: string): boolean => {
  return bcrypt.compareSync(pass, hash);
}
